Page({
    data: {
      citys: '请选择所在地区',
      userId: wx.getStorageSync('userId'),
      name: '',
      city: '',
      county: '',
      userTel: '',
      province: '',
      detailAddress: '',

      isClick: true,
    },

    //数据绑定
    bindname (e) {
      // console.log(e)

      this.setData({
        name: e.detail.value
      })
    },

    bindUsertel(e) {

      this.setData({
        userTel: e.detail.value
      })

    },

    binddetailAddress (e) {
      this.setData({
        detailAddress: e.detail.value
      })
    },

    bindPickerChange (e) {
      console.log(e)
      this.setData({
        province: e.detail.value[0],
        city: e.detail.value[1],
        county: e.detail.value[2],
        citys: e.detail.value[0] + '-' + e.detail.value[1] + '-' + e.detail.value[2]
      })
    },

    addLocation2 () {
      return false
    },
    //添加地址确认按钮
    addLocation () {

      var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
        if (this.data.name==0) {
          wx.showToast({
            title: '请输入真实姓名',
            icon: 'none'
          })
          return;
        }
        if (!myreg.test (this.data.userTel)) {
          wx.showToast({
            title: '请输入正确手机号',
            icon: 'none'
          })
          return;
        }

      if (this.data.citys == '请选择所在地区') {
        wx.showToast({
          title: '请选择所在地区',
          icon: 'none'
        })
        return;

        }

       if (this.data.detailAddress==0) {
         wx.showToast({
           title: '请输入详细地址',
           icon: 'none'
         })
         return;
       }
       var params = {
         userId: this.data.userId,
         name : this.data.name,
         userTel: this.data.userTel,
         city: this.data.city,
         county: this.data.county,
         province: this.data.province,
         detailAddress: this.data.detailAddress
       }
        this.addLocationApi(params)
    },

    addLocationApi (params) {
      var _this = this
      this.setData({
        isClick: false
      })
      wx.request({
        url: 'https://devapi.xiaoshitimebank.com/user/sdx/sdx/address/mod/auth',
        data: params,
        method: 'POST',
        header: {
          "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
        "token" : wx.getStorageSync('token'),
          "uid" : wx.getStorageSync('uuid')
        },
        success: (res) => {
          if (res.data.code == 200) {
            _this.setData({
              isClick: true
            })
            wx.showToast({
              title: '添加成功',
              icon: 'none',
              duration: 1000
            })
            // setTimeout(function () {
              wx.navigateBack()
            // },1000)
          }else{
            _this.setData({
              isClick: true
            })
            wx.showToast({
              title: res.data.msg,
              icon: 'none'
            })
          }
        }
      })
    }
})
